/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-11-08
 * Time: 0:16
 */

//动态规划一>买卖股票的最佳时机含手续费:
public class Demo {
    public int maxProfit(int[] prices, int fee) {
        int n = prices.length;
        int[] f = new int[n]; int[] g = new int[n];
        f[0] = -prices[0];

        for(int i = 1; i <= n-1; i++){
            f[i] = Math.max(f[i-1],g[i-1]-prices[i]);
            g[i] = Math.max(g[i-1],f[i-1]+prices[i]-fee);
        }
        return g[n-1];
    }
}
